home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / presto / presto10.lha / src / unix_timer.C < prev    next >
C/C++ Source or Header  |  1991-12-11  |  677b  |  54 lines

  1.  
  2. /*
  3.  * Unix support for timer object.
  4.  *
  5.  */
  6.  
  7. #include <stddef.h>
  8. #include <time.h>
  9. #include "presto.h"
  10.  
  11. void
  12. Timer::init()
  13. {
  14.     t_starttime = getabsolutetime();
  15. }
  16.  
  17. Timer::~Timer()
  18. {
  19. }
  20.  
  21.  
  22. double
  23. Timer::getabsolutetime()
  24. {
  25.     struct timeval *t_tv;
  26.     
  27.     t_tv = getdaytime();
  28.     return (double)t_tv->tv_sec +
  29.         ((double)(t_tv->tv_usec) * 1.0e-6);
  30. }
  31.  
  32. char*
  33. Timer::getasciitime()
  34. {
  35.     struct timeval *t_tv;
  36.     t_tv = getdaytime();
  37.     return ctime((time_t *)&t_tv->tv_sec);
  38. }
  39.  
  40.  
  41. struct timeval* 
  42. Timer::getdaytime()
  43. {
  44.     gettimeofday(&t_time,(struct timezone *)0);
  45.     return &t_time;
  46. }
  47.  
  48. void
  49. Timer::print(ostream& s)
  50. {
  51.     s << form("(Timer)this= 0x%x,", this) << 
  52.          "t_starttime = " << t_starttime;
  53. }
  54.